Skip to content

feat: add Opaque API and Protobuf Editions support #5723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

kop
Copy link

@kop kop commented Jul 8, 2025

This pull request introduces significant updates to the code generation logic, with a focus on supporting Protobuf Editions and adding a new "Opaque API" mode for improved flexibility in request handling. Key changes include updating supported features for Protobuf Editions, integrating the useOpaqueAPI flag across the generator, and modifying templates to conditionally handle the Opaque API logic.

These changes enhance the flexibility and capability of the code generator, ensuring compatibility with the latest Protobuf standards while providing developers with options to tailor the generated code to their specific needs.

References to other Issues or PRs

Fixes #4555

Have you read the Contributing Guidelines?

Yes

Brief description of what is fixed or changed

Protobuf Editions Support:
  • internal/codegenerator/supported_features.go: Added support for Protobuf Editions by updating supportedCodeGeneratorFeatures to include FEATURE_SUPPORTS_EDITIONS and declaring edition 2023 in the new supportedEditions function. Updated methods to include minimum and maximum supported editions in plugin responses.
Opaque API Feature:

@kop kop marked this pull request as ready for review July 8, 2025 20:24
@kop kop mentioned this pull request Jul 8, 2025
Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool! Please add some test files that set this new option so I can see what the code looks like when it's generated. You'll need to add a new opaque.buf.gen.yaml or so, see the other generation scripts in examples/internal/proto/examplepb. Thanks!

@kop
Copy link
Author

kop commented Jul 16, 2025

@johanbrandhorst, thank you for review!
I've added example files with generated code and mention of editions support and opaque API in README.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets rename the option to align with the Go protobuf plugin

@johanbrandhorst
Copy link
Collaborator

Protolint is failing because the new file isn't formatted, run buf format -w. The gorelease job is failing because of an issue with a dependency, rebase on main to fix it.

@kop
Copy link
Author

kop commented Jul 25, 2025

@johanbrandhorst, I’ve fixed the formatting and resolved most of the Bazel build errors. However, one issue remains — it’s caused by the opaque.proto examples requiring different compilation settings. I’m not very familiar with Bazel, so I’d really appreciate your help in resolving this.

@johanbrandhorst
Copy link
Collaborator

Oh boy, Bazel isn't my strong suite either unfortunately. It seems like the error we're seeing is

opaque.pb.gw.go:53:28: cannot use runtime.String(val) (value of type string) as *string value in assignment

So the problem is probably setting the right generator options for protoc-gen-go. I don't really know what we need to do here, but I'll CC @AlejoAsd who I know has some Bazel skills :)

@ar3s3ru
Copy link

ar3s3ru commented Aug 1, 2025

@johanbrandhorst @kop seems like you need to pass use_opaque_api to the go_proto_compiler in ./BUILD.bazel here, under options: https://github.com/kop/grpc-gateway/blob/1167ac0c21585be992a45b393e7845a6f732d8f1/BUILD.bazel#L56-L70

I'd assume you don't want to use the Opaque API for all protos in the repository, but scoped to the example folder you touched right?

If so, maybe it'd be a good idea to create a new go_proto_compiler in ./BUILD.bazel like so:

go_proto_compiler(
    name = "go_grpc_use_opaque_api",
    options = [
        "paths=source_relative",
        "require_unimplemented_servers=false",
        "use_opaque_api=true", # The relevant change
    ],
    plugin = "@org_golang_google_grpc_cmd_protoc_gen_go_grpc//:protoc-gen-go-grpc",
    suffix = "_grpc.pb.go",
    visibility = ["//visibility:public"],
    deps = PROTO_RUNTIME_DEPS + [
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//codes:go_default_library",
        "@org_golang_google_grpc//status:go_default_library",
    ],
)

And then update the go_proto_library target in examples/internal/proto/examplepb/BUILD.bazel to use the new compiler:

<         "//:go_grpc",
---
>         "//:go_grpc_use_opaque_api",
168c168

@johanbrandhorst
Copy link
Collaborator

Thanks a lot for your input!

I'd assume you don't want to use the Opaque API for all protos in the repository, but scoped to the example folder you touched right?

Yes, ideally. We might even want to scope it less than that tbh, maybe only the file we're using here. I'd have to dig in a bit more and unfortunately I don't have time right now, but this might be good enough for someone to start on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Protobuf Editions
4 participants